# 爬取https://www.aqistudy.cn/historydata/ 网站全部城市

import requests
from lxml import etree

if __name__ == '__main__':
    # 爬取到页面源码数据
    url = 'https://www.aqistudy.cn/historydata/'
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.3'}
    page_text = requests.get(url=url, headers=headers).text

    tree = etree.HTML(page_text)
    # 解析到人们城市和所有城市对应的a标签
    # div/ul/li/a
    # div/ul/div[2]/li/a
    a_list = tree.xpath('//div[@class="bottom"]/ul/li | //div[@class="bottom"]/ul/div[2]/li')

    all_city_name = []
    for li in a_list:
        city_name = li.xpath('./a/text()')[0]
        all_city_name.append(city_name)

    print(all_city_name, len(all_city_name))
